import UIKit

class MainController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        addChildViewControllers()
//        print(tabBar.classForCoder) 通过KVC改变了只读属性"tabBar"
        let TabBarView = MainTabBar()
        setValue(TabBarView, forKey: "tabBar")
//        print(tabBar.classForCoder)
        TabBarView.plusbtn.addTarget(self, action: "btndidclick", forControlEvents: .TouchUpInside)
    }
   //MARK: 添加所有的视图控制器

    func addChildViewControllers() {
        addChildViewController(HomeViewController(), TitleName: "主页", ImageName: "tabbar_home")
        addChildViewController(MessageViewController(), TitleName: "消息", ImageName: "tabbar_message_center")
        addChildViewController(DiscoverViewController(), TitleName: "发现", ImageName: "tabbar_discover")
        addChildViewController(ProfileViewController(), TitleName: "我的", ImageName: "tabbar_profile")
    }
    /**
     添加单个的视图控制器
     - parameter ChildController: 控制器
     - parameter TitleName:       item文字
     - parameter ImageName:       item图片
     */
    func addChildViewController (ChildController:UIViewController,TitleName:String,ImageName:String) {
        let vc = UINavigationController(rootViewController: ChildController)
//        tabBar.tintColor = UIColor.orangeColor()
        ChildController.title = TitleName
        ChildController.tabBarItem.image = UIImage(named: ImageName)
        //改变tintColor  改变渲染颜色

        /*
        UIImageRenderingModeAutomatic  // 根据图片的使用环境和所处的绘图上下文自动调整渲染模式。
        UIImageRenderingModeAlwaysOriginal   // 始终绘制图片原始状态，不使用Tint Color,使用原生样式进行渲染
        UIImageRenderingModeAlwaysTemplate   // 始终根据Tint Color绘制图片，忽略图片的颜色信息。
        */
        ChildController.tabBarItem.selectedImage = UIImage(named: ImageName+"_highlighted")?.imageWithRenderingMode(.AlwaysOriginal)
        ChildController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:themeColor], forState: .Selected)
        
        addChildViewController(vc)
    }
    func btndidclick () {
        print("btndidclick")
    }
}
